package com.test.io;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.channels.FileChannel;

/**
 * 文件的快速拷贝
 */
public class NIOFileChannel {
    public static void main(String[] args) throws Exception{
        //创建相关流
        FileInputStream fileInputStream = new FileInputStream("D://6.picture//aa.jpg");
        FileOutputStream fileOutputStream = new FileOutputStream("D://6.picture//bb.jpg");

        //获取各个流对应的filechannel
        FileChannel sourceCh = fileInputStream.getChannel();
        FileChannel deatCh = fileOutputStream.getChannel();

        //使用transferForm完成拷贝
        deatCh.transferFrom(sourceCh,0,sourceCh.size());

        //关闭相关的通道和流
        sourceCh.close();
        deatCh.close();
        fileInputStream.close();
        fileOutputStream.close();
    }
}
